﻿package ui{
	import flash.display.Sprite
	import flash.display.Stage
	import flash.events.Event
	import flash.text.TextFormatAlign
	
	import flash.events.MouseEvent
	import flash.events.KeyboardEvent
	
	import ui.components.*
	import ui.components.scroll.*
	import playerio.*;
	
	public class Prompt extends Box{
		private var base:Box 
		private var input:Input;
		private var _callback:Function
		function Prompt(stage:Stage, text:String, value:String, callback:Function){
			_callback = callback
			fill(0xffffff,.8).add(
				new Box().minSize(300,110).fill(0x0,.5,10).margin(10,10,10,10).add(
					new Box().minSize(300,110).fill(0xFFFFFF,1,10).margin(0,0,0,0).add(
						new Box().margin(10).add(
							new Label(text, 20)
						)	
					).add(
						new Box().margin(43,20,NaN,20).add(
							new Box().margin(2,0,0,3).minSize(20,25).fill(0x666666,0,5).border(1,0x444444,1).add(
								input = new Input(value,14, TextFormatAlign.CENTER).setStyle(false,false)
							)
						)
					).add(
						new Box().margin(75).add(
							new TextButton("Join game",accept)
						)
					)
				)
			)
			
			stage.addChild(this);
			
			
			stage.addEventListener(Event.RESIZE, handleResize)
			handleResize()
		}
		
		function accept():void{
			if(input.text != ""){
				stage.removeEventListener(Event.RESIZE, handleResize)
				stage.removeChild(this);
				_callback(input.text)
			}
		}
		
		private function handleResize(e:Event = null){
			this.width = stage.stageWidth
			this.height = stage.stageHeight
		}
	}
}